﻿using System.Collections.Generic;
using IQIGame.Onigao.GamePlay;


namespace IQIGame.Onigao.Logic
{
    public class BuffComponent : TComponent
    {
        public Unit unit;
        public List<BuffHandler> buffList = new List<BuffHandler>();
        public List<BuffHandler> makerBuffList = new List<BuffHandler>();
        
        
        
        public Dictionary<EBuffCustomState, int> buffState = new Dictionary<EBuffCustomState, int>();
        
        public Dictionary<int, int> replaceSkill = new Dictionary<int, int>();

        public ShieldController shield;
        
        protected override void OnDispose()
        {
            for (int i = 0; i < this.buffList.Count; i++)
            {
                this.Destroy(this.buffList[i]);
            }
            this.buffList.Clear();
            this.makerBuffList.Clear();
        }

        public override void OnCreate(TEntity entity)
        {
            this.unit = entity as Unit;
            this.shield = new ShieldController(this);
        }

        public void OnRefresh()
        {
            for (int i = 0; i < this.buffList.Count; i++)
            {
                var rBuff = this.buffList[i];
                rBuff.OnRefresh(this.unit.battle.playCtrl.realRound);
            }
        }

        public void OnDot(EBuffDotTriggerType rTriggerType)
        {
            for (int i = 0; i < this.buffList.Count; i++)
            {
                var rBuff = this.buffList[i];
                rBuff.OnDot(rTriggerType);
                if (this.unit.IsDead(true))
                {
                    break;
                }
            }
        }
        
        public void OnDead()
        {
            for (int i = 0; i < this.buffList.Count; i++)
            {
                var rBuff = this.buffList[i];
                this.Destroy(rBuff);
            }
        }
        
        public void Relive()
        {
            
        }
    }
}